/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i1,st,ed) for(int i1 = st,j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) foR( i , st , ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip( X ) sleep( X )
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

class P8XMatrixRecovery {
public:
    vector <string> solve(vector <string> rows, vector <string> columns);
};

inline bool _Match(string &str1,string &str2) {
    fo(i,LN(str1)) {
        if ( str1[i]!=str2[i] && (str1[i]!='?' && str2[i]!='?') ) {
            return false;
        }
    }
    return true;
}
vector< vector<int> > E;
bitset< 40 > used;
int mt[40];
bool try_kuhn( int v ) {
    if ( used[v] ) {
        return false;
    }
    used[v]=1;
    fo(i,SZ(E[v])) {
        int w = E[v][i];
        if ( mt[w]==-1 || try_kuhn( mt[w] ) ) {
            mt[w]=v;
            return true;
        }
    }
    return false;
}
int R,C;
vector<string> vi;
vector<string> G;

inline bool perfectmatch() {
    E.assign(SZ(vi),vector<int>());
    fo(i,SZ(vi)) {
        string s1=vi[i];

        fo(j,SZ(G)) {
            string s2=G[j];
            if ( _Match(s1,s2) ) {
                E[i].pb(j);
            }
        }
    }

    SET(mt,-1);
    fo(i,SZ(vi)) {
        used=0;
        try_kuhn(i);
    }
    fo(i,SZ(vi)) {
        if ( mt[i]==-1 )return false;
    }
    return true;

}
vector <string> P8XMatrixRecovery :: solve(vector <string> rows, vector <string> columns) {
    R = SZ( rows );
    C = SZ( columns );
    G.clear();
    G = columns;

    fo(i,R) {
        fo(j,C) {
            if ( rows[i][j]=='?' ) {
                rows[i][j]='0';

                // build graph
                vi.clear();
                fo(m,C) {
                    string s1="";
                    fo(n,R) {
                        s1+=rows[n][m];
                    }
                    vi.pb(s1);
                }

                if ( !perfectmatch() ) {
                    rows[i][j]='1';
                }
            }
        }
    }

    return rows;
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, vector <string> p0, vector <string> p1, bool hasAnswer, vector <string> p2) {
    cout << "Test " << testNum << ": [" << "{";
    for (int i = 0; int(p0.size()) > i; ++i) {
        if (i > 0) {
            cout << ",";
        }
        cout << "\"" << p0[i] << "\"";
    }
    cout << "}" << "," << "{";
    for (int i = 0; int(p1.size()) > i; ++i) {
        if (i > 0) {
            cout << ",";
        }
        cout << "\"" << p1[i] << "\"";
    }
    cout << "}";
    cout << "]" << endl;
    P8XMatrixRecovery *obj;
    vector <string> answer;
    obj = new P8XMatrixRecovery();
    clock_t startTime = clock();
    answer = obj->solve(p0, p1);
    clock_t endTime = clock();
    delete obj;
    bool res;
    res = true;
    cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
    if (hasAnswer) {
        cout << "Desired answer:" << endl;
        cout << "\t" << "{";
        for (int i = 0; int(p2.size()) > i; ++i) {
            if (i > 0) {
                cout << ",";
            }
            cout << "\"" << p2[i] << "\"";
        }
        cout << "}" << endl;
    }
    cout << "Your answer:" << endl;
    cout << "\t" << "{";
    for (int i = 0; int(answer.size()) > i; ++i) {
        if (i > 0) {
            cout << ",";
        }
        cout << "\"" << answer[i] << "\"";
    }
    cout << "}" << endl;
    if (hasAnswer) {
        if (answer.size() != p2.size()) {
            res = false;
        } else {
            for (int i = 0; int(answer.size()) > i; ++i) {
                if (answer[i] != p2[i]) {
                    res = false;
                }
            }
        }
    }
    if (!res) {
        cout << "DOESN'T MATCH!!!!" << endl;
    } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
        cout << "FAIL the timeout" << endl;
        res = false;
    } else if (hasAnswer) {
        cout << "Match :-)" << endl;
    } else {
        cout << "OK, but is it right?" << endl;
    }
    cout << "" << endl;
    return res;
}
int main() {
    bool all_right;
    all_right = true;

    vector <string> p0;
    vector <string> p1;
    vector <string> p2;

    {
        // ----- test 0 -----
        string t0[] = {"10?","?11"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        string t1[] = {"01","10","1?"};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        string t2[] = {"101","011"};
        p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
        all_right = KawigiEdit_RunTest(0, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 1 -----
        string t0[] = {"0","?","1"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        string t1[] = {"0?1"};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        string t2[] = {"0","0","1"};
        p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
        all_right = KawigiEdit_RunTest(1, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 2 -----
        string t0[] = {"10","01"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        string t1[] = {"10","01"};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        string t2[] = {"10","01"};
        p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
        all_right = KawigiEdit_RunTest(2, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 3 -----
        string t0[] = {"?" "?0","11?","?01","1?1"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        string t1[] = {"1?" "?" "?","?111","0?1?"};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        string t2[] = {"010","110","101","101"};
        p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
        all_right = KawigiEdit_RunTest(3, p0, p1, true, p2) && all_right;
        // ------------------
    }

    if (all_right) {
        cout << "You're a stud (at least on the example cases)!" << endl;
    } else {
        cout << "Some of the test cases had errors." << endl;
    }
    return 0;
}
// END KAWIGIEDIT TESTING
//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
// kate: indent-mode cstyle; space-indent on; indent-width 0; 
